import java.util.Hashtable;
import org.jcsp.lang.AltingChannelInput;
import org.jcsp.lang.CSProcess;
import org.jcsp.lang.Channel;
import org.jcsp.lang.ChannelOutput;
import org.jcsp.lang.One2OneChannel;
import org.jcsp.lang.Parallel;

/**
 * 
 * @author Tiago Ferreto
 * @author Ramon Costi Fernandes <ramon.fernandes@acad.pucrs.br>
 */
public class Main {

	public static void main(String[] args) {

//		// Canais para comunicacao da console de comando com os nodos.
//		final One2OneChannel cons0 = Channel.one2one();
//		final One2OneChannel cons1 = Channel.one2one();
//		final One2OneChannel cons2 = Channel.one2one();
//		final One2OneChannel cons3 = Channel.one2one();
//		final One2OneChannel cons4 = Channel.one2one();
//		final One2OneChannel cons5 = Channel.one2one();
//		final One2OneChannel cons6 = Channel.one2one();
//		final One2OneChannel cons7 = Channel.one2one();
//
//		// Canais para comunicacao dos nodos com o hub.
//		final One2OneChannel chan0A = Channel.one2one();
//		final One2OneChannel chan1A = Channel.one2one();
//		final One2OneChannel chan2A = Channel.one2one();
//		final One2OneChannel chan3A = Channel.one2one();
//		final One2OneChannel chan4A = Channel.one2one();
//		final One2OneChannel chan5A = Channel.one2one();
//		final One2OneChannel chan6A = Channel.one2one();
//		final One2OneChannel chan7A = Channel.one2one();
//
//		// Canais para comunicacao do hub com os nodos.
//		final One2OneChannel chan0B = Channel.one2one();
//		final One2OneChannel chan1B = Channel.one2one();
//		final One2OneChannel chan2B = Channel.one2one();
//		final One2OneChannel chan3B = Channel.one2one();
//		final One2OneChannel chan4B = Channel.one2one();
//		final One2OneChannel chan5B = Channel.one2one();
//		final One2OneChannel chan6B = Channel.one2one();
//		final One2OneChannel chan7B = Channel.one2one();

		// Instanciacao dos processos Nodos.
//		CSProcess node0 = new Node("Node 0", "00:00:00:00:00:A1", chan0A.in(), cons0.in(), chan0B.out());
//		CSProcess node1 = new Node("Node 1", "00:00:00:00:00:B2", chan1A.in(), cons1.in(), chan1B.out());
//		CSProcess node2 = new Node("Node 2", "00:00:00:00:00:C3", chan2A.in(), cons2.in(), chan2B.out());
//		CSProcess node3 = new Node("Node 3", "00:00:00:00:00:D4", chan3A.in(), cons3.in(), chan3B.out());
//		CSProcess node4 = new Node("Node 4", "00:00:00:00:00:E5", chan4A.in(), cons4.in(), chan4B.out());
//		CSProcess node5 = new Node("Node 5", "00:00:00:00:00:F6", chan5A.in(), cons5.in(), chan5B.out());
//		CSProcess node6 = new Node("Node 6", "00:00:00:00:01:A7", chan6A.in(), cons6.in(), chan6B.out());
//		CSProcess node7 = new Node("Node 7", "00:00:00:00:02:B8", chan7A.in(), cons7.in(), chan7B.out());

            
            
		// Instanciacao do processo Hub os canais devidamente mapeados em
		// arrays.
//		ChannelOutput[] hubOuts = { chan0A.out(), chan1A.out(), chan2A.out(), chan3A.out(), chan4A.out(), chan5A.out(), chan6A.out(), chan7A.out() };
//		AltingChannelInput[] hubIns = { chan0B.in(), chan1B.in(), chan2B.in(), chan3B.in(), chan4B.in(), chan5B.in(), chan6B.in(), chan7B.in() };
//		CSProcess hub = new Hub(hubIns, hubOuts);
//
//		// Instanciacao da console de comandos e associacao dos nodos com seus
//		// canais de comunicacao.
//		NodeChannelWrapper[] nodes = { new NodeChannelWrapper(node0, cons0.out()), new NodeChannelWrapper(node1, cons1.out()),
//				new NodeChannelWrapper(node2, cons2.out()), new NodeChannelWrapper(node3, cons3.out()), new NodeChannelWrapper(node4, cons4.out()),
//				new NodeChannelWrapper(node5, cons5.out()), new NodeChannelWrapper(node6, cons6.out()), new NodeChannelWrapper(node7, cons7.out()) };
//		CSProcess console = new CommandConsole(nodes);
                 
		// Execucao dos processos em paralelo.
            
		//CSProcess[] processes = { node0, node1, hub, console };
		//CSProcess simulator = new Parallel(processes);
		//simulator.run();
            
            CommandConsole console = new CommandConsole(); 
            Topology tp = console.selectTopology();
            CSProcess[] TPprocesses = tp.getProcesses();
            
            CSProcess[] processes = new CSProcess[TPprocesses.length+1];
            for(int i =0;i<TPprocesses.length;i++){
                processes[i] = TPprocesses[i];
            }
            processes[TPprocesses.length] = console;
            CSProcess simulator = new Parallel(processes);
            simulator.run();  
            
            
        }
        
}
